<template>
	<view class="school_content">
		<view class="page">
			<view class="task-list">
				<view class="task-list-card">
					<view class="task-list-left">实验室</view>
					<view class="task-list-right">{{room_name}}</view>
				</view>
				<view class="task-list-card">
					<view class="task-list-left">设备名</view>
					<view class="task-list-right">{{equipment_name}}</view>
				</view>
			</view>


			<view class="task-title">申请信息</view>
			<view class="task-list" style="margin-bottom: 30rpx;padding-bottom: 20rpx;">

				<view class="task-list-card">
					<view class="task-list-left" style="display:block;width:100%;">预约时间</view>
				</view>
				<view class="task-list-card">
					<view class="weui-cells" style="margin-top:0px;line-height:auto;height:auto;font-size:16px;">
						<view class="weui-cell" style="padding:unset;height:40px;line-height: 40px;">
							<view class="weui-cell__hd">
								{{booking_wdate}} {{booking_wtime}}
							</view>
						</view>
					</view>

				</view>

				<view class="task-list-card">
					<view class="task-list-left" style="display:block;width:100%;"><span style="color:red">*</span>预约人单位
					</view>
				</view>
				<view class="task-list-card">

					<view class="weui-cells" style="margin-top:0px;line-height:auto;width:70px;float:left;">
						<view class="weui-cell weui-cell_select weui-cell_select-before"
							style="padding-right:0px;width:70px;">

							<view class="weui-cell__hd" style="display: inline-block;width:70px;">
								<picker indicator-class="picker_cu" class="task2_sq_input" style="width:70px;"
									indicator-style="width:70px;height:50px;color:red;" :value="collegetypeIndex"
									@change="bindcollegetypeChange" :range="collegetypeList">
									<view class="picker" style="font-size:14px;" v-if="collegetypeIndex>-1">
										{{collegetypeList[collegetypeIndex]}}
									</view>
								</picker>
							</view>
						</view>
					</view>
					<view v-if="collegetypeIndex==0" class="weui-cells"
						style="margin-top:0px;line-height:auto;width:calc(100% - 84px);float:right;">
						<view class="weui-cell weui-cell_select weui-cell_select-before"
							style="padding-right:0px;width:100%;">

							<view class="weui-cell__hd" style="display: inline-block;width:100%;">

								<picker indicator-class="picker_cu" class="task2_sq_input"
									style="width:100%;float:left;"
									indicator-style="width:calc(100% - 84px);height:50px;color:red;"
									:value="collegeIndex" @change="bindcollegeChange" :range="collegeList">
									<view class="picker" style="font-size:14px;" v-if="collegeIndex>-1">
										{{collegeList[collegeIndex]}}
									</view>
									<view class="picker" style="font-size:14px;" v-else>
										请选择
									</view>
								</picker>

							</view>
						</view>
					</view>

					<view v-if="collegetypeIndex==1" class="weui-cells"
						style="margin-top:0px;line-height:auto;width:calc(100% - 84px);float:right;">
						<view class="weui-cell weui-cell_select" style="padding-right:0px;width:100%;">

							<view class="weui-cell__hd" style="display: inline-block;width:100%;">

								<input type="text" class="task2_sq_input" style="width:100%;float:left;font-size:14px;"
									placeholder="请输入单位" @input="bindcollegeinputtext" :value="collegevalue" />

							</view>
						</view>
					</view>

				</view>

				<template v-for="(item,index) in task2fields">
					<template v-if="item.type=='textarea'">
						<view class="task-list-card">
							<view class="task-list-left" style="display:block;width:100%;">
								<text v-if="item.required=='checked'" style="color:red">*</text>{{item.cname}}：
							</view>
							<view class="task-list-right"></view>
						</view>
						<view class="task-list-card" style="height: 152px;">

							<view class="task-list-right" style="width: 100%;height: 152px;text-align:left;">

								<textarea fixed wrap="hard" auto_height="true" maxlength="-1" @input="bindinputtext"
									:data-index="index" :data-ename="item.ename" :value="item.val" name="desc"
									data-field="desc" class="weui-textarea" placeholder="请输入"
									style="font-size:14px;font-weight:normal;border:1px solid #ebeef5;padding-left:4px;margin-right:1px;width: 96%;" />

							</view>
						</view>
					</template>
					<template v-else-if="item.type=='checkbox'">
						<view class="task-list-card">
							<view class="task-list-left" style="display:block;width:100%;">
								<text v-if="item.required=='checked'" style="color:red">*</text>{{item.cname}}：
							</view>

						</view>
						<view class="task-list-card">
							<view class="task-list-right"
								style="width: 100%;height:auto;text-align:left;white-space: normal;">
								<template v-for="(checkboxitem,checkbox_idx) in item.vals">
									<label class="checkbox">
										<checkbox :value="checkboxitem" />{{checkboxitem}}
									</label>

								</template>
							</view>
						</view>
					</template>
					<template v-else>
						<view class="task-list-card">
							<view class="task-list-left" style="display:block;width:100%;">
								<text v-if="item.required=='checked'" style="color:red">*</text>{{item.cname}}：
							</view>
						</view>
						<view class="task-list-card">
							<view class="task-list-right" style="display:block;width:100%;white-space: normal;">
								<template v-if="item.type=='text'">
									<input type="text" class="task2_sq_input" :data-index="index" placeholder="请输入"
										:data-ename="item.ename" :value="item.val" @input="bindinputtext" />
								</template>
								<template v-else-if="item.type=='select'">

									<view class="weui-cells" style="margin-top:0px;line-height:auto;">
										<view class="weui-cell weui-cell_select weui-cell_select-before"
											style="padding-right:0px;">
											<view class="weui-cell__hd" style="display: inline-block;width:100%;">
												<picker class="task2_sq_input" :value="item.val" :data-index="index"
													:data-ename="item.ename" @change="bindSelectChange"
													:range="item.vals">
													<view class="picker" style="font-size:14px;">
														{{item.val}}
													</view>
												</picker>

											</view>
										</view>
									</view>
								</template>

								<template v-else-if="item.type=='number'">
									<input type="number" class="task2_sq_input" :value="itme.val" placeholder="请输入"
										:data-index="index" :data-ename="item.ename" @input="bindinputnumber" />
								</template>

								<template v-else-if="item.type=='mobile'">
									<input type="text" disabled="disabled" readonly="true" :value="item.val"
										placeholder="点击右边按钮授权" style="width:calc(100% - 160rpx);float:left;"
										class="task2_sq_input" />
									<button
										style="width: 45px;padding: 7px 6px;line-height: 30px;height: 40px;float: right;margin-left: 10px;padding-right: 0px;margin-right: 0px;padding-left: 0px;"
										:data-index="index" :data-ename="item.ename" open-type="getPhoneNumber"
										@getphonenumber="getPhoneNumber">
										<image src="@/static/images/tel.png" style="height:24px;width:24px;">
										</image>
									</button></template>

								<template v-else-if="item.type=='date'">
									<picker class="task2_sq_input" mode="date" :value="item.val" :data-index="index"
										:data-ename="item.ename" start="2020-12-01" end="2100-12-31"
										@change="bindDateChange">
										<view class="picker">
											{{item.val}}
										</view>
									</picker>
								</template>

								<template v-else-if="item.type=='time'">

									<picker mode="time" class="task2_sq_input" :data-index="index"
										:data-ename="item.ename" :value="item.val" start="00:01" end="23:59"
										@change="bindTimeChange">
										<view class="picker">
											{{item.val}}
										</view>
									</picker>

								</template>

							</view>
						</view>
					</template>

				</template>



			</view>
			<view class="task-list" v-if="desc.length>0">
				<view class="task-list-card">
					<view class="task-list-left">注意事项</view>
					<view class="task-list-right"></view>
				</view>
				<view class="task-list-card">
					<view class="task-list-right"
						style="width:100%;text-align:left;height:auto;overflow: scroll;white-space:unset;text-overflow:unset;">
						<text>{{desc}}</text>
					</view>
				</view>
			</view>


		</view>

		<view class="posttasktobookingBtnparent">
			<view @click="posttasktobooking" class="posttasktobookingBtn">提 交</view>
		</view>

	</view>
</template>

<script>
	import {
		formatTime,
		formatLocation,
		dateUtils,
		getWeekByDate,
		formatDate
	} from '@/common/util.js';
	export default {
		data() {
			return {
				tid: 0,
				id: 0,
				title: '',

				endtime: '',
				num: 0,
				desc: '',
				fields_arr: [],
				task2fields: [],
				date: '2020-12-01',
				time: '12:01',
				sex: '男',
				sexList: ['男', '女'],
				mobile: "",
				name: '',
				age: '',
				type: 0,
				mode: 0,
				startdate: '',
				enddate: '',
				advancedate: 0,
				visitdate: 0,
				weeks: 0,
				weeksStr: "",
				datetime: [],
				weekdate: "",
				weekdatetimerange: "",
				weekdatess: '2020-12-01',

				years: [],
				year: "",
				yearskey: 0,
				currentweekyear: 0,
				months: [],
				month: 2,
				monthskey: 0,
				currentweekmonth: 1,
				days: [],
				day: 2,
				dayskey: 0,
				currentweekday: "",
				value: [9999, 2, 3],
				isDaytime: true,
				currentweekdayName: '',
				datetimeArr: [],
				equipmentlistArr: [],
				datetimeArrVal: -1,
				datetimeArrIndex: -1,
				booking_wdate: "",
				booking_datetonum: null,
				booking_mode: 0,
				booking_eid: -1,
				booking_tno: -1,
				booking_edn_id: -1,
				weekdateArr: [],
				multiIndex: [0, 0],
				multiArray: [
					[],
					[]
				],
				weekdatetimeArr: [],
				weekdatetimeArrAll: [],
				pickerIndex: -1,
				equipment_name: "",
				room_name: "",
				equipment_desc: "",
				isloading: 0,
				detail_encryptedData: "",
				detail_iv: "",
				detail_index: "",
				detail_ename: "",
				session_key: "",
				collegeIndex: -1,
				collegeObjectList: [],
				collegeList: [],
				collegetypeIndex: 0,
				collegetypeList: ["校内", "校外"],
				collegevalue: "",
			}
		},
		onLoad(options) {

			const date = new Date()
			this.year = date.getFullYear()
			const startYear = date.getFullYear();
			const endYear = date.getFullYear() + 1;

			let years = []
			for (let i = startYear; i <= endYear; i++) {
				years.push(i)
			}
			this.years = years

			let months = []
			for (let i = 1; i <= 12; i++) {
				months.push(i)
			}
			this.months = months

			let days = []
			for (let i = 1; i <= 31; i++) {
				days.push(i)
			}
			this.days = days

			this.booking_eid = options.id

			const dateformat = formatDate(date, '-');
			if (uni.getStorageSync('task2fieldsflag') && uni.getStorageSync('task2fieldsflag') != "") {
				let task2fieldsflag = uni.getStorageSync('task2fieldsflag');
				if (task2fieldsflag != dateformat) {
					this.clearwxStorage();
				}
			} else {
				uni.setStorageSync('task2fieldsflag', dateformat);
			}

			let booking_wtime = "";
			if (options.wtime) {
				booking_wtime = options.wtime;
			}
			if (options.wdate && options.mode && options.wtno) {
				this.booking_wdate = options.wdate
				this.booking_wtime = options.wtime
				this.booking_mode = options.mode
				this.booking_tno = options.wtno
			}
			this.gettask();
			this.getcollegelist();
			this.makeSessionkey(0);

		},
		methods: {
			bindcollegeinputtext: function(e) {
				const value = e.detail.value;
				uni.setStorageSync('collegevalue', value);

				this.collegevalue = value

			},
			bindcollegetypeChange: function(e) {

				const index = e.detail.value;
				uni.setStorageSync('collegetypeIndex', index);
				uni.removeStorageSync('collegevalue');
				uni.removeStorageSync('collegeIndex');

				this.collegetypeIndex = index
				this.collegevalue = ''
				this.collegeIndex = -1

			},
			bindAccountChange: function(e) {

				const index = e.detail.value;

				const weekdatetimeArrAll = this.data.weekdatetimeArrAll;
				const booking_wdate = weekdatetimeArrAll[index][0]['cname'];
				const tno = weekdatetimeArrAll[index][0]['tno'];
				const edn_id = weekdatetimeArrAll[index][0]['edn_id'];


				this.pickerIndex = index
				this.booking_wdate = booking_wdate
				this.booking_wtime = ""
				this.booking_tno = tno
				this.booking_edn_id = edn_id

			},
			bindMultiPickerChange: function(e) {
				const index = e.detail.value;
				const weekdatetimeArrAll = this.weekdatetimeArrAll;
				const curweekdatetimeArrAll = weekdatetimeArrAll[index[0]][index[1]];
				const booking_wdate = this.weekdateArr[index[0]];
				const booking_wtime = curweekdatetimeArrAll['cname'];
				const tno = curweekdatetimeArrAll['tno'];
				const edn_id = curweekdatetimeArrAll['edn_id'];

				this.multiIndex = e.detail.value
				this.booking_wdate = booking_wdate
				this.booking_wtime = booking_wtime
				this.booking_tno = tno
				this.booking_edn_id = edn_id


			},
			bindMultiPickerColumnChange: function(e) {
				const weekdatetimeArr = this.weekdatetimeArr;
				const curweekdatetimeArr = weekdatetimeArr[e.detail.value];


				let multiArray = this.multiArray
				let multiIndex = this.multiIndex



				multiIndex[e.detail.column] = e.detail.value;


				switch (e.detail.column) {
					case 0:
						multiArray[1] = curweekdatetimeArr;
						multiIndex[1] = 0;
						break;
				}
				this.multiArray = multiArray
				this.multiIndex = multiIndex

			},

			bindSelectChange: function(e) {
				console.log('e=', e)
				const index = e.currentTarget.dataset.index;
				const ename = e.currentTarget.dataset.ename;
				const value = e.detail.value;
				let task2fields = this.task2fields;
				const vals = task2fields[index]['vals'];
				const val = vals[value];
				task2fields[index]['val'] = val;
				uni.setStorageSync('task2fields', JSON.stringify(task2fields));

				this.task2fields = task2fields

			},
			bindDateChange: function(e) {

				const index = e.currentTarget.dataset.index;
				const ename = e.currentTarget.dataset.ename;
				const val = e.detail.value;
				let task2fields = this.task2fields;
				task2fields[index]['val'] = val;
				uni.setStorageSync('task2fields', JSON.stringify(task2fields));

				this.task2fields = task2fields

			},
			bindDateChange2: function(e) {

				const ename = e.currentTarget.dataset.ename;

				const val = e.detail.value;


				const valdate = this.years[val[0]] + '-' + this.months[val[1]] + '-' + this.days[val[2]];



				const currentweekdayName = getWeekByDate(valdate);

				this.year = this.data.years[val[0]]
				this.month = this.data.months[val[1]]
				this.day = this.data.days[val[2]]

				this.currentweekdayName = currentweekdayName
				this.$set(ename, valdate)

			},
			bindTimeChange: function(e) {
				const index = e.currentTarget.dataset.index;
				const ename = e.currentTarget.dataset.ename;
				const val = e.detail.value;
				let task2fields = this.task2fields;
				task2fields[index]['val'] = val;
				uni.setStorageSync('task2fields', JSON.stringify(task2fields));

				this.task2fields = task2fields

			},
			bindinputtext: function(e) {
				const index = e.currentTarget.dataset.index;
				const ename = e.currentTarget.dataset.ename;
				const val = e.detail.value;
				let task2fields = this.task2fields;
				task2fields[index]['val'] = val;
				uni.setStorageSync('task2fields', JSON.stringify(task2fields));

				this.task2fields = task2fields

			},

			bindinputnumber: function(e) {
				const index = e.currentTarget.dataset.index;
				const ename = e.currentTarget.dataset.ename;
				const val = e.detail.value;
				let task2fields = this.task2fields;
				task2fields[index]['val'] = val;
				uni.setStorageSync('task2fields', JSON.stringify(task2fields));

				this.task2fields = task2fields

			},

			bindDatetimeArrSelectChange: function(e) {
				const index = e.currentTarget.dataset.index;
				const ename = e.currentTarget.dataset.ename;
				const val = e.detail.value;
				this.$set(ename, val)

			},
			getPhoneNumber: function(e) {

				const index = e.currentTarget.dataset.index;
				const ename = e.currentTarget.dataset.ename;
				var that = this;
				if (e.detail.errMsg == 'getPhoneNumber:ok') {

					that.detail_encryptedData = e.detail.encryptedData
					that.detail_iv = e.detail.iv
					that.detail_index = index
					that.detail_ename = ename
					that.fl_client_userbindmobile(that.detail_encryptedData, that.detail_iv, that.detail_index, that
						.detail_ename);
				}

			},
			fl_client_userbindmobile: function(encryptedData, iv, index, ename) {

				uni.showLoading({
					title: '加载中...',
				})
				const that = this;
				const session_key = this.data.session_key;
				let url = 'api/user/tomobile2?token=' + uni.getStorageSync('token');

				let params = {
					encryptedData: encodeURIComponent(encryptedData),
					iv: encodeURIComponent(iv),
					token: uni.getStorageSync('token'),
					session_key: encodeURIComponent(session_key)
				}

				this.$request.request(url, params, 0, 'post', false).then(res => {

					if (res.data.status == 1) {

						const mobile = res.data.data.mobile;
						let task2fields = that.task2fields;
						task2fields[index]['val'] = mobile;

						that.task2fields = task2fields

					} else if (res.data.status == -3) {
						uni.showToast({
							title: "" + res.data.msg,
							icon: 'none',
							duration: 3000,
							success: function() {

							}
						})
					} else {
						uni.showToast({
							title: "" + res.data.msg,
							icon: 'none',
							duration: 3000,
							success: function() {
								if (res.data.status == -2) {
									uni.removeStorageSync('token');
									uni.removeStorageSync('isuser');
									setTimeout(() => {
										uni.redirectTo({
											url: '../login/index?redirect_page=toequipbooking&id=' +
												that.booking_eid +
												'&wdate=' + that.booking_wdate +
												'&wtime=' + that.booking_wtime +
												'&edn_id=' + that.booking_edn_id +
												'&wmode=' + that.booking_mode +
												'&wtno=' + that.booking_tno,
										})
									}, 3000)
								}
							}
						});
					}
					uni.hideLoading();
				})
			},
			clearwxStorage: function() {
				uni.removeStorageSync('collegevalue');
				uni.removeStorageSync('collegeIndex');
				uni.removeStorageSync('collegetypeIndex');
				uni.removeStorageSync('task2fields');
				uni.removeStorageSync('task2fieldsflag');
			},
			makeSessionkey: function(flag) {
				var that = this;
				// #ifdef MP-WEIXIN
				uni.login({
					success(res) {
						if (res.code) {
							let url = 'api/user/makeSessionkey?token=' + wx
								.getStorageSync('token') + "&code=" + res.code
							that.$request.request(url, '', 0, 'get', false).then(res2 => {

								//发起网络请求

								let res2w = res2.data;
								if (typeof res2w == 'string') {
									let str22 = res2w.replace(/\ufeff/g, ""); //去除反斜杠
									res2w = JSON.parse(str22); //string转object
								}
								if (res2w.status == 1) {
									const res2_data_data = res2w.data;
									const session_key = res2_data_data.session_key;

									that.session_key = session_key

								} else {

									uni.showModal({
										title: "提示",
										content: res2w.msg,
										success: function(t) {

										}
									})
								}
							})
						} else {
							console.log('登录失败！' + res.errMsg)
						}
					},
					fail(err) {
						console.log('登录失败！' + err.errMsg)

					}
				})

				// #endif
			},
			gettask: function() {
				uni.showLoading({
					title: '加载中...',
				})
				const that = this;
				const url = 'api/task/taskbookingequipinfo?id=' + this.booking_eid + '&wtno=' + this.booking_tno +
					'&wdate=' + this.booking_wdate + '&token=' + uni.getStorageSync('token');
				that.$request.request(url, '', 0, 'get', false).then(res => {

					let res2w = res.data;
					if (typeof res2w == 'string') {
						let str22 = res2w.replace(/\ufeff/g, ""); //去除反斜杠
						res2w = JSON.parse(str22); //string转object
					}
					if (res2w.status == 1) {
						const res2_data_data = res2w.data;
						const tid = res2_data_data.tid;
						const title = res2_data_data.title;
						const type = res2_data_data.type;
						const mode = res2_data_data.mode;
						const startdate = res2_data_data.startdate;
						const enddate = res2_data_data.enddate;
						const fields_arr = res2_data_data.fields_arr;
						const desc = res2_data_data.desc;
						let task2fields = res2_data_data.task2fields;
						const advancedate = res2_data_data.advancedate;
						const visitdate = res2_data_data.visitdate;
						const weeks = res2_data_data.weeks;
						const datetime = res2_data_data.datetime;
						const weeksStr = res2_data_data.weeksStr;
						const equipment_name = res2_data_data.equipment_name;
						const room_name = res2_data_data.room_name;
						const equipment_desc = res2_data_data.equipment_desc;
						const datetimeArr = res2_data_data.datetimeArr;
						const equipmentlistArr = res2_data_data.equipmentlistArr ? res2_data_data
							.equipmentlistArr : [];
						const weekdateArr = res2_data_data.weekdateArr;
						const weekdatetimeArr = res2_data_data.weekdatetimeArr;
						const weekdatetimeArrAll = res2_data_data.weekdatetimeArrAll;
						const usertype = res2_data_data.usertype ? res2_data_data.usertype : '';
						let multiArray = [
							[],
							[]
						];
						if (mode == 2) {
							multiArray[0] = weekdateArr;
							multiArray[1] = weekdatetimeArr.length > 0 ? weekdatetimeArr[0] : [];
						}
						if (uni.getStorageSync('task2fields') && uni.getStorageSync('task2fields') != "") {
							task2fields = uni.getStorageSync('task2fields');
							task2fields = JSON.parse(task2fields);
						}

						that.equipment_name = equipment_name
						that.equipment_desc = equipment_desc
						that.usertype = usertype
						that.tid = tid
						that.datetimeArr = datetimeArr
						that.equipmentlistArr = equipmentlistArr
						that.title = title
						that.type = type
						that.booking_mode = mode
						that.startdate = startdate
						that.enddate = enddate
						that.fields_arr = fields_arr
						that.desc = desc
						that.task2fields = task2fields
						that.advancedate = advancedate
						that.visitdate = visitdate
						that.weeks = weeks
						that.datetime = datetime
						that.weeksStr = weeksStr
						that.weekdateArr = weekdateArr
						that.multiArray = multiArray
						that.weekdatetimeArr = weekdatetimeArr
						that.weekdatetimeArrAll = weekdatetimeArrAll
						that.room_name = room_name


						if (uni.getStorageSync('collegevalue') && uni.getStorageSync('collegevalue') != "") {
							that.collegevalue = uni.getStorageSync('collegevalue')
						}

						if (uni.getStorageSync('collegeIndex') && uni.getStorageSync('collegeIndex') != "") {

							that.collegeIndex = uni.getStorageSync('collegeIndex')

						}

						if (uni.getStorageSync('collegetypeIndex') && uni.getStorageSync('collegetypeIndex') !=
							"") {

							that.collegetypeIndex = uni.getStorageSync('collegetypeIndex')

						}

					} else if (res2w.status == -2) {

						uni.showToast({
							title: "" + res2w.msg,
							icon: 'none',
							duration: 3000,
							success: function() {

							}
						});
						uni.removeStorageSync('token');
						uni.removeStorageSync('isuser');

						setTimeout(() => {
							uni.redirectTo({
								url: '../login/index?redirect_page=toequipbooking&id=' + that
									.booking_eid + '&wdate=' + that.booking_wdate + '&wtime=' +
									that.booking_wtime + '&edn_id=' + that.booking_edn_id +
									'&wmode=' + that.booking_mode + '&wtno=' + that
									.booking_tno,
							})
						}, 3000);

					} else {


						uni.showToast({
							title: "" + res2w.msg,
							icon: 'none',
							duration: 3000
						});

						setTimeout(function() {
							uni.navigateBack({
								fail: function() {
									uni.redirectTo({
										url: '../index/index',
									})
								}
							})
						}, '3000')

					}

					uni.hideLoading();


				})

			},

			getcollegelist: function() {

				const that = this;
				const url = 'api/college/index?token=' + uni.getStorageSync('token');
				that.$request.request(url, '', 0, 'get', false).then(res => {

					let res2w = res.data;
					if (typeof res2w == 'string') {
						let str22 = res2w.replace(/\ufeff/g, ""); //去除反斜杠
						res2w = JSON.parse(str22); //string转object
					}
					if (res2w.status == 1) {
						const res2_data_data = res2w.data;
						const collegeObjectList = res2w.data.list;
						if (!collegeObjectList) collegeObjectList = [];
						let collegeList = [];
						collegeObjectList.forEach((item, index) => {
							collegeList[index] = item.name
						})

						that.collegeList = collegeList
						that.collegeObjectList = collegeObjectList

					} else {
						uni.showToast({
							title: "" + res2w.msg,
							icon: 'none',
							duration: 3000
						});
					}

				})

			},
			bindcollegeChange: function(e) {
				console.log('bindcollegeChange e', e)
				const index = e.detail.value;
				const collegeObjectList = this.collegeObjectList;
				const collegevalue = index > -1 ? collegeObjectList[index]['name'] : '';
				uni.setStorageSync('collegeIndex', index);
				uni.setStorageSync('collegevalue', collegevalue);

				this.collegeIndex = index
				this.collegevalue = collegevalue
				console.log('bindcollegeChange index', index)
				console.log('bindcollegeChange collegevalue', collegevalue)

			},
			savesubscribe: function(id, flag) {

				const that = this;
				const url = 'api/ebooking/subscribe?id=' + id + '&flag=' + flag + '&token=' + uni
					.getStorageSync('token');

				that.$request.request(url, '', 0, 'get', false).then(res => {

					if (res.data.status == 1) {} else if (res.data.status == -2) {} else {}

				})
			},
			posttasktobooking: function() {
				console.log('save start-------------------------------')
				const that = this;

				const id = this.id;
				const task2fields = this.task2fields;
				
				console.log('task2fields=',task2fields)
				
				
				if (this.booking_wdate == "") {
					uni.showToast({
						title: '预约时间不正确',
						icon: 'none',
					})
					return;
				}
				console.log('save start-------------------------------预约时间不正确')

				if (this.booking_tno < 0) {
					uni.showToast({
						title: '预约时段不正确',
						icon: 'none',
					})
					return;
				}
				console.log('save start-------------------------------预约人单位不能为空')

				if (this.collegevalue == '') {
					uni.showToast({
						title: '预约人单位不能为空',
						icon: 'none',
					})
					return;
				}

				console.log('save start-------------------------------提交中task2fields',task2fields)

				let showmessage = '';
				let flag = 0;
				task2fields.forEach((item, index) => {

					if (flag == 0 && item.required == 'checked' && item.val == '') {
						showmessage = item.cname + '为必填项';
						flag = 1;
					}
					
					console.log('index=',index)
					console.log('item=',item)
					
				})
				console.log('save start-------------------------------为必填项')
				if (showmessage != '') {

					uni.showToast({
						title: showmessage,
						icon: 'none',
					})
					return;
				}

				if (this.isloading == 1) return;

				uni.showLoading({
					title: '提交中',
				})

				console.log('save start-------------------------------提交中')

				this.isloading = 1

				var url = 'api/task/tasktobooking?token=' + uni.getStorageSync('token');

				let params = {
					tid: that.tid,
					booking_date: that.booking_wdate,
					id: that.booking_eid,
					booking_time: that.booking_wtime,
					booking_mode: that.booking_mode,
					booking_eid: that.booking_eid,
					booking_tno: that.booking_tno,
					task2fields: task2fields,
					collegevalue: that.collegevalue
				}
				console.log('222save start-------------------------------为必填项',task2fields)
				
				that.$request.request(url, params, 0, 'POST', false).then(res => {
					let res2w = res.data;
					if (typeof res2w == 'string') {
						let str22 = res2w.replace(/\ufeff/g, ""); //去除反斜杠
						res2w = JSON.parse(str22); //string转object
					}
					if (res2w.status == 1) {
						uni.hideLoading();
						uni.removeStorageSync('collegevalue');
						uni.removeStorageSync('collegeIndex');
						uni.removeStorageSync('collegetypeIndex');
						uni.removeStorageSync('task2fields');

						const res2_data_data = res2w.data;

						const bookingid = res2w.data.bookingid;
						// #ifdef MP-WEIXIN
						uni.requestSubscribeMessage({
							tmplIds: ['hmTQyi4NJMzgkAzsrU8ZD_npzAG-js5vLad7BSIm5qM',
								'iEvRcIpzDDKMOMG0TArOeuGO985Wy1kO9_jFyrMyCyY'
							],
							success(res) {
								if (res['iEvRcIpzDDKMOMG0TArOeuGO985Wy1kO9_jFyrMyCyY'] ==
									'accept' && res[
										'hmTQyi4NJMzgkAzsrU8ZD_npzAG-js5vLad7BSIm5qM'] ==
									'accept') {
									that.savesubscribe(bookingid, 3)
								} else if (res[
										'hmTQyi4NJMzgkAzsrU8ZD_npzAG-js5vLad7BSIm5qM'] ==
									'accept'
								) {
									that.savesubscribe(bookingid, 2)
								} else if (res[
										'iEvRcIpzDDKMOMG0TArOeuGO985Wy1kO9_jFyrMyCyY'] ==
									'accept'
								) {
									that.savesubscribe(bookingid, 1)
								}
								uni.reLaunch({
									url: '/pages/school/myequiplist/index'
								})

							},
							fail(res) {
								uni.reLaunch({
									url: '/pages/school/myequiplist/index'
								})
							}
						})
						// #endif
						
						// #ifdef H5
								uni.reLaunch({
									url: '/pages/school/myequiplist/index'
								})
						// #endif

					} else if (res2w.status == -2) {
						uni.hideLoading();
						uni.showToast({
							title: "" + res2w.msg,
							icon: 'none',
							duration: 3000,
							success: function() {

							}
						});
						uni.removeStorageSync('token');
						uni.removeStorageSync('isuser');


						setTimeout(() => {
							uni.redirectTo({
								url: '../login/index?redirect_page=toequipbooking&id=' + that
									.booking_eid + '&wdate=' + that.booking_wdate + '&wtime=' +
									that.booking_wtime + '&wmode=' + that.booking_mode +
									'&wtno=' + that.booking_tno,
							})
						}, 3000);

					} else {

						uni.hideLoading();

						that.isloading = 0


						uni.showToast({
							title: "" + res2w.msg,
							icon: 'none',
							duration: 3000,
							success: function() {

							}
						});
					}
				})
			},
		}
	}
</script>

<style>
	.page {
		height: 100%;
		overflow-y: auto;
	}

	/* 列表 */
	.task-title {
		float: left;
		height: 32rpx;
		line-height: 32rpx;
		margin: 0 24rpx 24rpx 24rpx;
		padding-left: 16rpx;
		font-size: 32rpx;
		border-left: 4px solid #409eff;
	}

	.task-title:first-child {
		margin: 24rpx;
	}

	.task-list {
		float: left;
		width: calc(100% - 50rpx);
		margin: 0 24rpx 24rpx 24rpx;
		background: #fff;
		border: 0px solid #ebeef5;
		border-radius: 8rpx;
	}

	.task-list-card {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		padding: 20rpx 20rpx;
	}

	.task-list ul {
		float: left;
	}

	.task-list ul li {
		float: left;
		width: calc(100% - 72rpx);
		height: 84rpx;
		line-height: 84rpx;
		padding: 0 36rpx;
		font-size: 28rpx;
		border-bottom: 0px solid #ebeef5;
		overflow: hidden;
	}

	.task-list-left {
		float: left;
		width: 160rpx;
		font-weight: bold;
		color: #999;
	}

	.task-list-right {
		float: right;
		width: calc(100% - 160rpx);
		color: #333;
		text-align: right;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}


	.task2_sq_input {
		text-align: left;
		display: block;
		height: 80rpx;
		line-height: 80rpx;
		border: 1px solid #ebeef5;
		padding-left: 4px;

	}

	.textarea {
		font-size: 14px;
		width: 100%;
		padding: 0px 0px;
		padding-left: 4px;
	}

	.picker_cu {
		font-size: 16px;
		font-weight: bold;
		color: red;
	}

	.posttasktobookingBtnparent {
		display: flex;
		width: 100%;
		text-align: center;
		justify-content: center;
	}

	.posttasktobookingBtn {

		background-color: #019ec9;
		width: 368rpx;
		height: 80rpx;
		line-height: 80rpx;
		background-color: #07c160;
		color: white;
		cursor: pointer;
		margin-bottom: 60rpx;
	}
</style>